<?php

/**
 * 获取职位筛选条件
 * Created by PhpStorm.
 * User: yaosj
 * Date: 15-10-9
 * Time: 下午8:51
 */
class GetFilter implements iController {

    public function output($queryArgs) {

        global $cmsdb;
        //通过province来判断是否是查看省职位信息
        $otherJobArea = array(); //用来记录哪个省需要开启其他工作的查询

        if (isset($queryArgs['province']))
            $sql = 'SELECT  o.* FROM  original_ztk_area o';
        else
            $sql = 'SELECT  o.* FROM  original_ztk_area o , data_job_major d WHERE o.id = d.area_id GROUP BY o.id';
        $theA = $cmsdb->getResults($sql);
        foreach ($theA as $area) {
            //将国家转化成中央
            if ($area->name == '国家')
                $areaArray[] = array(
                    'id' => $area->id,
                    'name' => '中央'
                );
            else $areaArray[] = array(
                'id' => $area->id,
                'name' => $area->name
            );
            //设置激活的省职位表
            if ($area -> is_job_activated > 0) {
                $activateProvinces[] = array(
                    'id' => $area -> id,
                    'name' => $area -> name
                );
                if($area -> is_job_activated == 2 )
                    $otherJobArea[] = $area ->id;
            }
        }

        if (!isset($queryArgs['province'])) {

            array_unshift($areaArray,array('id' => 0,'name'=>'不限'));
            $political = array('不限', '群众', '中共党员', '共青团员');
            $degree = array(
                array('id' => 0, 'name' => '专科'),
                array('id' => 1, 'name' => '学士'),
                array('id' => 2, 'name' => '硕士'),
                array('id' => 3, 'name' => '博士')
            );
            $juniorYear = array(
                array('id' => '-', name => '不限'),
                array('id' => 0, 'name' => '无'),
                array('id' => 1, 'name' => '一年'),
                array('id' => 2, 'name' => '二年'),
                array('id' => 3, 'name' => '三年'),
                array('id' => 4, 'name' => '四年'),
                array('id' => 5, 'name' => '五年及以上')
            );
            $otherJob = array(
                array('id' => '-', 'name' => '不限'),
                array('id' => 'none', 'name' => '无'),
                array('id' => 'is_3_1', 'name' => '三支一服大学生'),
                array('id' => 'is_west_volunteer', 'name' => '西部志愿者'),
                array('id' => 'is_college_officer', 'name' => '大学生村官'),
                array('id' => 'is_special_teacher', 'name' => '特岗计划教师')
            );

            return genOutput(1, array(
                'area' => $areaArray,
                'degree' => $degree,
                'political' => $political,
                'junior_year' => $juniorYear,
                'other_job' => $otherJob,
                'activate_province' => $activateProvinces));

        } else{

            $junior0 = array(
                'name' => '性别',
                'option' => array(
                    array('id' => '男','name' => '男'),
                    array('id' => '女','name' => '女'))
            );
            $sql = 'SELECT  distinct(area) area FROM  data_province_job_major WHERE province =:pro';
            $theA = $cmsdb -> getResults($sql,array(':pro' => trim($queryArgs['province'])));
            $areaA2[] = array(id => '不限',name => '不限');
            foreach ($theA as $area) {
                $areaA2[] = array( 'id' => $area -> area,'name' => $area -> area);
            }
            $junior1 = array(
                'name' => '地区',
                'option' => $areaA2
            );

            $degree = array(
                array('id' => -1, 'name' => '高中（中专）'),
                array('id' => 0, 'name' => '大专'),
                array('id' => 1, 'name' => '学士'),
                array('id' => 2, 'name' => '硕士'),
                array('id' => 3, 'name' => '博士')
            );
            $junior2 = array(
                'name' => '学历',
                'option' => $degree
            );

            $senior0 = array(
                name =>'政治面貌',
                option => array(
                    array('id' => '中共党员', 'name' => '中共党员'),
                    array('id' => '团员', 'name' => '团员'),
                    array('id' => '群众', 'name' => '群众'),
                    array('id' => '群', 'name' => '民主党派'))
            );

            $senior1 = array(
                name => '基层工作时间',
                option => array(
                    array('id' => 0, 'name' => '无'),
                    array('id' => 1, 'name' => '一年'),
                    array('id' => 2, 'name' => '两年'),
                    array('id' => 3, 'name' => '三年'),
                    array('id' => 4, 'name' => '四年'),
                    array('id' => 5, 'name' => '五年及以上'))
            );

            if (in_array($queryArgs['province'],$otherJobArea)) {

                $sql = 'SELECT  distinct(other_job) other_job  FROM  data_province_job_major WHERE province =:pro ';
                $theA = $cmsdb -> getResults($sql,array(':pro' => trim($queryArgs['province'])));
                $oj[] = array(id => '无',name => '无');
                foreach ($theA as $o) {
                    if (empty($o -> other_job) || '不限' == $o -> other_job)
                        continue;
                    $oj[] = array( 'id' => $o -> other_job,'name' => $o -> other_job);
                }

                $senior2 = array(
                    'name' => '其他工作经历',
                    'option' => $oj
                );
            } else if (14 == $queryArgs['province']) {
                $senior2 = array (
                    'name' => '考生身份',
                    'option' => array(
                        array('id' => '0', 'name' => '外省上学的福建籍应届生'),
                        array('id' => '1', 'name' => '本省上学的非福建籍应届生'),
                        array('id' => '2', 'name' => '福建户籍人员'),
                        array('id' => '3', 'name' => '非福建户籍人员'))
                );

            }  else {
                $senior2 = array(
                    'name' => '是否四项目人员',
                    'option' => array(
                        array('id' => '0', 'name' => '否'),
                        array('id' => '1', 'name' => '是'))
                );
            }

            return genOutput(1, array(
                'junior_0' => $junior0,
                'junior_1' => $junior1,
                'junior_2' => $junior2,
                'senior_0' => $senior0,
                'senior_1' => $senior1,
                'senior_2' => $senior2
            ));
        }
    }
}